#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Windows服务安装验证脚本
"""

import os
import sys
from pathlib import Path

def verify_service_setup():
    """验证服务安装所需的文件和路径"""
    print("========================================")
    print("WMS Simple 服务安装验证")
    print("========================================")
    print()
    
    # 检查项目根目录
    project_root = Path(__file__).parent.parent
    print(f"项目根目录: {project_root}")
    print(f"项目根目录存在: {'✅' if project_root.exists() else '❌'}")
    print()
    
    # 检查虚拟环境Python
    venv_python = Path(r"D:\python\wms_env\Scripts\python.exe")
    print(f"虚拟环境Python: {venv_python}")
    print(f"虚拟环境Python存在: {'✅' if venv_python.exists() else '❌'}")
    print()
    
    # 检查服务脚本
    service_script = project_root / "wms_service.py"
    print(f"服务脚本: {service_script}")
    print(f"服务脚本存在: {'✅' if service_script.exists() else '❌'}")
    print()
    
    # 检查当前Python环境
    current_python = sys.executable
    print(f"当前Python: {current_python}")
    print(f"是否在虚拟环境: {'✅' if 'wms_env' in current_python else '❌'}")
    print()
    
    # 构建服务路径
    service_path = f'"{venv_python}" "{service_script}"'
    print(f"服务安装路径: {service_path}")
    print()
    
    # 测试服务脚本语法
    print("测试服务脚本语法...")
    try:
        import subprocess
        result = subprocess.run([
            str(venv_python), "-m", "py_compile", str(service_script)
        ], capture_output=True, text=True, timeout=10)
        
        if result.returncode == 0:
            print("✅ 服务脚本语法正确")
        else:
            print("❌ 服务脚本语法错误:")
            print(result.stderr)
    except Exception as e:
        print(f"❌ 测试服务脚本时发生错误: {e}")
    
    print()
    
    # 检查依赖包
    print("检查虚拟环境依赖包...")
    try:
        result = subprocess.run([
            str(venv_python), "-c", 
            "import win32serviceutil, win32service, win32event, servicemanager; print('pywin32: ✅')"
        ], capture_output=True, text=True, timeout=10)
        
        if result.returncode == 0:
            print(result.stdout.strip())
        else:
            print("❌ pywin32包未正确安装")
            print(result.stderr)
    except Exception as e:
        print(f"❌ 检查依赖包时发生错误: {e}")
    
    print()
    print("验证完成！")

if __name__ == "__main__":
    verify_service_setup() 